package com.cx.base.presenter;

import android.content.Intent;
import android.text.TextUtils;

import com.cx.base.view.IView;
import com.cx.base.view.load.LoadingController;

import io.reactivex.disposables.CompositeDisposable;

/**
 * Author by ziv, Email wuming5445@dingtalk.com, Date on 2020/9/29.
 */
public class BasePresenter<T extends IView>
        implements IPresenter.Presenter<T> {
    private String TAG = this.getClass().getName();
    protected T mView;

    @Override
    public void onStart() {

    }

    protected void init() {

    }

    @Override
    public void onDestroy() {
        mView = null;
    }

    @Override
    public void attachView(T t) {
        mView = t;
        mView.addPresenter(this);
        init();
    }

    public LoadingController getLoadingController() {
        return mView.getLoadingController();
    }


    public CompositeDisposable getDisposable() {
        return mView.getDisposable();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

    }

    public void showMsg(String msg) {
        if (!TextUtils.isEmpty(msg) && mView != null)
            mView.showToast(msg);
    }
}
